﻿using MediatR;
using System.CJL.API.Application.Command.FinishedProductsCommand;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.FinishedProductsCommandHanler
{
    /// <summary>
	/// 成品添加
	/// </summary>
	public class FinishedProductsAddCommandHandler : IRequestHandler<FinishedProductsAddCommand,int>
	{
		IFinishedProductRepositry _repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="repository"></param>
        public FinishedProductsAddCommandHandler(IFinishedProductRepositry repository)
        {
			_repository=repository;
		}

		public async Task<int> Handle(FinishedProductsAddCommand request, CancellationToken cancellationToken)
		{
			return await _repository.Addasync(new Domain.FinishedProduct
			{
				finishedProductNumbering=request.finishedProductNumbering,
				finishedProductName = request.finishedProductName,
				finishedProductModel = request.finishedProductModel,
				finishedProductUnit = request.finishedProductUnit,
				finishedProductUpperLimit = request.finishedProductUpperLimit,
				finishedProductDays = request.finishedProductDays,
				finishedProductBatch = request.finishedProductBatch,
				finishedProductLowerLimit = request.finishedProductLowerLimit,
				finishedProductState = request.finishedProductState,
				finishedProductRemark = request.finishedProductRemark,
				finishedProductImg = request.finishedProductImg,
				AddName = request.AddName,
				AddTime = DateTime.Now.ToUniversalTime(),
			});
		}
	}
}
